package com.boot.security.server.dao.mffl;

import java.util.List;
import java.util.Map;

import com.boot.security.server.model.mffl.Vo.MfflInformationVo;
import org.apache.ibatis.annotations.*;

import com.boot.security.server.model.mffl.MfflInformation;

@Mapper
public interface MfflInformationDao {

    MfflInformation getById(@Param("id") Long id);

    MfflInformationVo getMfflInformationVoById(Long id);

    @Delete("delete from mffl_information where id = #{id}")
    int delete(Long id);

    int update(MfflInformation mfflInformation);

    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    @Insert("insert into mffl_information(title, identityStatus, user_id, type, image_url, partial_content, createTime, updateTime) values(#{title}, #{identityStatus}, #{userId}, #{type}, #{imageUrl}, #{partialContent}, #{createTime}, #{updateTime})")
    int save(MfflInformation mfflInformation);

    int count(@Param("params") Map<String, Object> params);

    List<MfflInformation> list(@Param("params") Map<String, Object> params, @Param("offset") Integer offset, @Param("limit") Integer limit);

    //资讯-资讯列表
    int topicCount(@Param("params") Map<String, Object> params);
    //资讯-资讯列表
    List<MfflInformationVo> topicList(@Param("params") Map<String, Object> params, @Param("offset") Integer offset, @Param("limit") Integer limit);

    //我的话题-我的发布(根据userId查询)
    List<MfflInformationVo> getMyInformationList(@Param("userId") Long id);

    //我的话题-逻辑删除
    @Update("update mffl_information set delete_state = 0,deleteTime = now() where id = #{informationId}")
    int delMyInformation(@Param("informationId") long informationId);

    //我的-我的收藏
    List<MfflInformationVo> getMyCollectList(@Param("userId") Long userId);
    //资讯-增加热度
    @Update("update mffl_information set hot = hot+1 where id = #{informationId} ")
    void saveInformationHot(@Param("informationId") long informationId);

    //根据分类获取资讯
    @Select("select * from mffl_information where type = #{type} and delete_state = 1 ")
    List<MfflInformation> getMyInformationListByType(@Param("type") Long type);

    @Select("select count(*) from mffl_information where type = #{type} and delete_state = 1 ")
    int getMyInformationCountByType(@Param("type") Long type);
}
